// test for class: Block Piece
// g++ -g -o fp block_test.cpp -I/home/sun/workspace/SDFS2 -I/home/sun/libs/muduo/include -L/home/sun/libs/muduo/lib -lmuduo_base -lmuduo_net -lpthread -lboost_system -lboost_filesystem

#include <muduo/base/Types.h>
#include <muduo/base/Logging.h>
#include <iostream>
#include <boost/shared_ptr.hpp>
#include <boost/any.hpp>
// #include <sdfs/common/ToolKit.h>
// #include <sdfs/storage/Block.h>
// #include <sdfs/storage/BlockStatus.h>
// #include <sdfs/common/File.h>
#include <vector>
#include <algorithm>

using namespace std;
using namespace boost;

/*

using namespace sdfs;
using namespace sdfs::common;
using namespace sdfs::storage;

const muduo::string blockpath = "/home/sun/sdfs_bin/4";

void block_test()
{
	muduo::string data1 = "NICE TO MEET YOU!";
	muduo::string data2 = "NICE TO MEET YOU, TOO!";
	muduo::string data3 = "GOOD TO SEE YOU";
	muduo::string data4 = "I USED TO HAVE A VERY GOOD MOOD";
	char buf[256];
	BlockPtr block(new Block(blockpath, 10));
	LOG_DEBUG << "block initialized";
	WriteOnlyFilePtr writer = block->getWriter();
	writer->write(data1.c_str(), data1.length());
	writer->write(data2.c_str(), data2.length());
	writer->write(data3.c_str(), data3.length());
	writer->write(data4.c_str(), data4.length()+1);
	
	ReadOnlyFilePtr reader = block->getReader();
	int n = reader->read(buf, 10);
	while(n > 0)
	{
		cout << "        " << "buf: "<< buf <<endl;
		n = reader->read(buf, 10);
	}
	cout << "        " << "buf: "<< buf <<endl;
	
}*/


class A
{
public:
	A(int v):v_(v){cout << "A()" << endl;};
	~A(){ cout << "~A()" << endl;};

 	bool operator < (const A& a) const
	{
		return v_ < a.v_ ? true : false;
	}

	bool operator == (const A& a)
	{
		cout << "v_: " << v_ <<" , a.v(): " << a.v() << endl;
		return v_ == a.v_ ? true : false;
	}

	bool operator == (shared_ptr<A>& a) const
	{
		cout << "v_: " << v_ <<" , a->v(): " << a->v() << endl;
		return v_ == a->v() ? true : false;
	}

	int v() const
	{
		return v_;
	}

private:
	int v_;
};


void anyptr_test()
{
	boost::any anyptr;
	{
		shared_ptr<A> sharedptr(new A(4));
		anyptr = sharedptr;
	}
	cout<< "end" << endl;
}
/*

struct SortFunction
{
	bool operator()(const shared_ptr<A>& p1,const shared_ptr<A>& p2)
	{
		cout << "sort: " << p1->v() << ", " << p2->v() << endl;
		return(*p1 < *p2);
	}
};

void sort_test()
{
	std::vector<boost::shared_ptr<A> > datas;
	for (int i = 4; i > 0; --i)
	{
		shared_ptr<A> a(new A(i));
		datas.push_back(a);
	}
	//shared_ptr<A> target(new A(2));
	// A target(2);
	// //std::vector<boost::shared_ptr<A> >::iterator r = std::find(datas.begin(), datas.end(), target);
	// shared_ptr<A> r = binaryFind<A>(datas, target);
	// assert(r != NULL);
	// cout << r->v() << endl;

	std::sort(datas.begin(), datas.end(), SortFunction());
	for (int i = 0; i < datas.size(); ++i)
	{
		cout << "data[" << i << "]=" << datas[i]->v() << endl;
	}
}
*/
int main()
{
	//cout << "=============block_test()===========" <<endl;
	anyptr_test();

	//sort_test();
}